Today I'm going to introduce a programming structure called the Wild Loop, also called Wild Do Loop.
And we're going to make a rotating coin by using that loop.
And we're also going to add power to the coin just because powers are cool and you can jump real high,
too.
So let's go ahead and get started with that.
I certainly to start with an empty world and then I'm going to save the coin off so that I can use it
in my game.
But I want to experiment in a world that's not my game in case I mess something up.
That's good practice.
So let's go to part.
Hit your little arrow, add a cylinder, and this is going to be our coin.
So let's call it coin.
Nice.
Let's make the brick color of that coin yellow.
There we go.
Let's make the material metal and hit an m and then down arrow one.
Now it's metal.
It's good down to the size and we'll make it 0.2 by two by two.
There.
That's very coin.
Like, let's move it up out of the ground.
Cool and then anchor it.
Anchored So don't fall can collide off so it doesn't stop us when we run into it.
Also for orientation.
Let's take a look at this real quick.
This is how we're going to make it spin.
So these are the axes of orientation, the axes of rotation, I should say, the X, Y and the Z.
We're going to rotate this coin around the Y axis.
If I change the Y to 30, we're going to get a 30 degree rotation of our coin.
There we go.
So you can see how we're going to program this.
Let's go ahead and do a control Z to put that back and we'll start coding.
Go to your coin, hit the plus, add a script.
We'll call this rotate.
All right, so got rotate.
And then in the rotate script, I can make this a bigger right.
Get a variable for your coin.
Local coin equals script parent.
And then we're going to make a function, local function, we'll call that rotate.
Right?
And in the rotate function we're going to add a while loop.
Now while loops repeat while a condition is true, we want the coin to continue to rotate until it's
destroyed.
So I am going to write true and that's going to make the y loop run forever or until it's destroyed.
Right.
So what we need to do is get our coin.
Every time we loop through this, we'll get the orientation and then set it equal to the coin's old
orientation plus a vector three new and then I write zero, five and zero.
I need to make this smaller so we can see it all in the screen.
Cool.
What is this doing?
It's taking the old orientation, which is three numbers an X, Y and Z.
So we need the vector three in order to hold an x, y and z.
I only want to change it on the y.
So I'm making these zero.
So we're essentially adding the x to the x, the Y or the Y, the z to the z.
The Y is the only thing changing.
But we also have to put a delay in this loop so that it doesn't crash our system.
Right.
This will run really, really, really fast.
I'll use up all the resources.
Boom, our system will freeze the weight with the no number is about 0.029 or 0.0 3 seconds.
If you put no number in it, it's going to look like this.
So some people will go like this thinking that that's a faster weight.
It's not right.
This is this is as fast as it gets.
So let's call our function and see what we have.
So we're not we didn't hook that up to any event.
So we actually have the right rotate there with the parentheses.
Let's hit the play button.
Let's see what we got.
And there's our coin and it's moving.
It's moving kind of slow.
I want to speed it up a little bit so I turn this off.
And I'm going to change this rotation to ten degree increments and then see how that works.
Yeah, that's a little bit better.
Now, if you make the wait longer, you're going to get, like, choppy movement.
And I'll show you how to do twinning, too.
That's like an animation.
It's a smooth movement.
We also have to smooth things down.
We'll do both of those.
But right now, this is going to be sufficient.
So here's our loop.
But we want to do special powers, too.
I'm going to go to the coin.
I'm going to add another script, hit that, plus add the script.
And this one is going to be collect, right?
The collect script.
Let's go ahead and get a variable.
Just like in our rotate.
Local coin equals script dot parent.
And then we'll make a function local function called on collect.
The other part will be the part that collects the coin.
That touches the coin.
So this is essentially a touched event that we're capturing.
So coin dot touched.
Connect that to on collect get rid of the two parentheses here because when we're connecting an event
to a function, we only need the function name.
All right.
So now other part could be anything, right?
It could be a ball.
It could be a tree.
We need something associated with the humanoid because the humanoid changes the walk, speed and the
jump power, just like the health.
Right.
Humanoids do a lot of stuff.
So I'm going to call that Luke HUME or local HUME.
Other part dot parent.
So this is a hand or a foot.
The parent is the character.
We'll do a colon, find first child, double quote, humanoid, right?
So if we find the humanoid, it's going to be right here in that variable.
If we don't find it, it's going to be nil.
So I'll say if.
HUME Then HUME Dot, we're going to use something called jump power, but something new in Roblox we
actually have to have this flag use jump power set to true, right?
That's new.
One of the reasons why I recreated this video, it used to not be there when used when use jump power
is set to true.
Now what we can do is say jump power equals and give it a value.
If you want you can look at your humanoid, find that jump power, see what the normal one is.
It's 50, so I'm going to make this 153 times the jump power.
We also have walk speed in your humanoid and that normally is 16.
I'm going to make this 50 so we can run real fast and then I'm going to get my coin and I'm going to
destroy it.
Cool.
Let's see what happens.
Hit the play.
There's our coin.
It's still spinning.
We have two scripts on it.
If we look in the workspace, open up the coin.
There's two scripts where I go ahead and touch it.
Boom!
Oh, we run real fast, jump real high, and the coin is gone.
All right, that's pretty cool.
So I'm going to save this coin off.
Go to my base plate.
I'm going to make it a model first.
I'm going to right click.
I'm going to say group.
Right.
Even though the top level was only one was only one thing called a coin.
I'm going to put it inside a model, which is like a fancy type of folder.
I'm going to call that coin.
All right.
And you could just save this off as the part with stuff underneath, but people usually don't.
So I right click on that.
Here we go a little quick.
Saved a Roblox coin.
You can put a description.
I'll say something like a coin with jump and run powers also rotates.
You could distribute to marketplace so other people could get it.
Or you could just hit submit.
There we go.
Now, when you go to your toolbox and you look under that, I saved another one off.
I saved my shack off, too.
We also need to save our health stuff.
This is under your inventory.
This is Marketplace.
And this is inventory and now we can just drag the coin in the world if we need it.
And it warns you that there are two scripts, but you wrote those scripts, so you're fine.
There it is way out there.
And you can move it around and do stuff with it.
All right.
So I will see you in the next video.
We will do a while loop that's configurable and we'll have a break condition in it.